package com.peanut.server.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.dto.TabCarBrandDTO;
import com.peanut.mapper.TabBrandMapper;
import com.peanut.pojo.TabCarBrand;
import com.peanut.server.TabBrandService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TabBrandServiceipml implements TabBrandService {
    @Resource
    private TabBrandMapper tabBrandMapper;

    @Override
    public List<TabCarBrandDTO> FindBrand() {
        List<TabCarBrandDTO> list = tabBrandMapper.selectAlls();
        String s = JSONObject.toJSONString(list);
        List<TabCarBrandDTO> tabBrandBOS = JSONObject.parseArray(s, TabCarBrandDTO.class);
        return tabBrandBOS;
    }
    //模糊查询
    @Override
    public List<TabCarBrandDTO> findBrandByName(String carName) {
        QueryWrapper<TabCarBrand> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("car)name",carName);
        List<TabCarBrandDTO> list=tabBrandMapper.selectList(queryWrapper);
        String s = JSONObject.toJSONString(list);
        List<TabCarBrandDTO> carTypeBOS=JSONObject.parseArray(s,TabCarBrandDTO.class);
        return carTypeBOS;
    }

    @Override
    public void addBrand(TabCarBrandDTO tabBrandBO) {
        TabCarBrand tabBrand=new TabCarBrand();
        tabBrand.setCarBrandId(tabBrandBO.getCarBrandId());//setId(tabBrandBO.getId());
        tabBrand.setCarName(tabBrandBO.getCarName());
        tabBrandMapper.insert(tabBrand);
    }

    @Override
    public void deleteBathByIdsBrand(List<Long> list) {
        tabBrandMapper.deleteBatchIds(list);

    }
}
